home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_DrawGauge.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  7KB  |  267 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. #ifdef DO_GAUGE_KIND
  10. VOID __regargs
  11. LTP_DrawTick(LayoutHandle *Handle,ObjectNode *Node,WORD Left,WORD Top)
  12. {
  13.     struct RastPort *rp = &Handle -> RPort;
  14.  
  15.     Left += Node -> Left;
  16.  
  17.     LTP_SetAPen(rp,Handle -> ShadowPen);
  18.     Move(rp,Left,Top);
  19.     Draw(rp,Left,Top + 1);
  20.  
  21.     LTP_SetAPen(rp,Handle -> ShinePen);
  22.     Move(rp,Left + 1,Top);
  23.     Draw(rp,Left + 1,Top + 1);
  24. }
  25.  
  26. VOID __regargs
  27. LTP_DrawGauge(LayoutHandle *handle,ObjectNode *node,LONG percent,BOOLEAN fullRefresh)
  28. {
  29.     struct RastPort        *rp = &handle -> RPort;
  30.     LONG            height    = node -> Height - (1 + 1);
  31.     LONG            width    = node -> Width - (2 + 2);
  32.     BOOLEAN            continuous;
  33.  
  34.     if(fullRefresh)
  35.     {
  36.         EraseRect(rp,node -> Left,node -> Top,node -> Left + node -> Width - 1,node -> Top + node -> Height - 1);
  37.  
  38.         if(node -> Special . Gauge . NoTicks)
  39.         {
  40.             DrawBevelBox(rp,node -> Left,node -> Top,node -> Width,node -> Height,
  41.                 GT_VisualInfo,    handle -> VisualInfo,
  42.                 GTBB_Recessed,    TRUE,
  43.             TAG_DONE);
  44.         }
  45.         else
  46.         {
  47.             LONG top = node -> Top + node -> Height - (handle -> RPort . TxHeight + 2);
  48.  
  49.             DrawBevelBox(rp,node -> Left,node -> Top,node -> Width,node -> Height - (handle -> InterHeight + handle -> RPort . TxHeight + 2),
  50.                 GT_VisualInfo,    handle -> VisualInfo,
  51.                 GTBB_Recessed,    TRUE,
  52.             TAG_DONE);
  53.  
  54.             LTP_SetPens(rp,handle -> TextPen,0,JAM1);
  55.  
  56.             LTP_PlaceText(handle,"0%",2,node -> Left,top + handle -> RPort . TxBaseline);
  57.             LTP_PlaceText(handle,"100%",4,node -> Left + node -> Width - TextLength(rp,"100%",4),top + handle -> RPort . TxBaseline);
  58.  
  59.             if(node -> Width >= TextLength(rp,"0%50%100%",9) + 4 * handle -> GlyphWidth)
  60.             {
  61.                 LONG i,left,total = node -> Width - 2;
  62.  
  63.                 LTP_PlaceText(handle,"50%",3,node -> Left + (node -> Width - TextLength(rp,"50%",3)) / 2,top + handle -> RPort . TxBaseline);
  64.  
  65.                 top -= handle -> InterHeight;
  66.  
  67.                 for (i = 0 ; i < 5 ; i++)
  68.                 {
  69.                     left = (total * i) / 4;
  70.  
  71.                     LTP_DrawTick(handle,node,left,top);
  72.                 }
  73.             }
  74.             else
  75.             {
  76.                 LONG i,left,total = node -> Width - 2;
  77.  
  78.                 top -= handle -> InterHeight;
  79.  
  80.                 for (i = 0; i < 3; i++)
  81.                 {
  82.                     left = (total * i) / 2;
  83.  
  84.                     LTP_DrawTick(handle,node,left,top);
  85.                 }
  86.             }
  87.         }
  88.     }
  89.  
  90.     if(node -> Special . Gauge . Discrete)
  91.     {
  92.         if(width < 60)
  93.             continuous = TRUE;
  94.         else
  95.             continuous = FALSE;
  96.     }
  97.     else
  98.         continuous = TRUE;
  99.  
  100.     if(!node -> Special . Gauge . NoTicks)
  101.         height -= handle -> InterHeight + handle -> RPort . TxHeight + 2;
  102.  
  103.     if(node -> Special . Gauge . InfoLength && node -> Special . Gauge . InfoText[0])
  104.     {
  105.         struct TextExtent    Extent;
  106.         LONG            len;
  107.         LONG            left;
  108.         LONG            right;
  109.  
  110.         left = 0;
  111.  
  112.         if(continuous)
  113.         {
  114.             right = (width * percent) / 100;
  115.  
  116.             if(right)
  117.             {
  118.                 LTP_SetAPen(rp,handle -> DrawInfo -> dri_Pens[FILLPEN]);
  119.  
  120.                 RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  121.             }
  122.         }
  123.         else
  124.         {
  125.             LONG count;
  126.  
  127.             right = 0;
  128.  
  129.             if(count = (10 * percent) / 100)
  130.             {
  131.                 LONG chunk = width / 10,i;
  132.                 UWORD fillPen = handle -> DrawInfo -> dri_Pens[FILLPEN];
  133.                 UWORD backPen = handle -> BackgroundPen;
  134.  
  135.                 for(i = 0 ; i < count ; i++)
  136.                 {
  137.                     LTP_SetAPen(rp,fillPen);
  138.                     RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + left + (chunk - 1) - 1,node -> Top + 1 + height - 1);
  139.  
  140.                     left += chunk;
  141.                     right += chunk;
  142.  
  143.                     LTP_SetAPen(rp,backPen);
  144.                     RectFill(rp,node -> Left + 2 + right - 1,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  145.                 }
  146.             }
  147.         }
  148.  
  149.         if(right < width)
  150.         {
  151.             left    = right;
  152.             right    = width;
  153.  
  154.             LTP_SetAPen(rp,handle -> BackgroundPen);
  155.             RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  156.         }
  157.  
  158.         if(handle -> DrawInfo -> dri_Pens[FILLTEXTPEN] == handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN])
  159.         {
  160.             if(handle -> DrawInfo -> dri_Pens[TEXTPEN] == handle -> DrawInfo -> dri_Pens[FILLPEN])
  161.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[TEXTPEN],handle -> BackgroundPen,JAM1 | COMPLEMENT);
  162.             else
  163.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[TEXTPEN],handle -> BackgroundPen,JAM1);
  164.         }
  165.         else
  166.         {
  167.             if(handle -> DrawInfo -> dri_Pens[FILLTEXTPEN] == handle -> DrawInfo -> dri_Pens[FILLPEN])
  168.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[FILLTEXTPEN],handle -> BackgroundPen,JAM1 | COMPLEMENT);
  169.             else
  170.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[FILLTEXTPEN],handle -> BackgroundPen,JAM1);
  171.         }
  172.  
  173.         len = TextFit(rp,node -> Special . Gauge . InfoText,strlen(node -> Special . Gauge . InfoText),&Extent,NULL,1,width,32767);
  174.  
  175.         LTP_PlaceText(handle,node -> Special . Gauge . InfoText,len,node -> Left + 2 + (width - Extent . te_Width) / 2,node -> Top + 1 + (height - rp -> Font -> tf_YSize) / 2 + rp -> Font -> tf_Baseline);
  176.  
  177.         LTP_SetPens(rp,handle -> TextPen,handle->BackgroundPen,JAM1);
  178.     }
  179.     else
  180.     {
  181.         LONG left,right;
  182.  
  183.         if(continuous)
  184.         {
  185.             if(node -> Current < percent)
  186.             {
  187.                 left    = (width * node -> Current) / 100;
  188.                 right    = (width * percent) / 100;
  189.  
  190.                 if(right)
  191.                 {
  192.                     LTP_SetAPen(rp,handle -> DrawInfo -> dri_Pens[FILLPEN]);
  193.                     RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  194.                 }
  195.             }
  196.             else
  197.             {
  198.                 if(node -> Current > percent)
  199.                 {
  200.                     left    = (width * percent) / 100;
  201.                     right    = (width * node -> Current) / 100;
  202.  
  203.                     if(right)
  204.                     {
  205.                         LTP_SetAPen(rp,handle -> BackgroundPen);
  206.                         RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  207.                     }
  208.                 }
  209.             }
  210.         }
  211.         else
  212.         {
  213.             LONG count;
  214.  
  215.             count = (10 * percent) / 100;
  216.  
  217.             if(!fullRefresh && count == node -> Special . Gauge . LastPercentage)
  218.             {
  219.                 node -> Current = percent;
  220.  
  221.                 LTP_PutStorage(node);
  222.  
  223.                 return;
  224.             }
  225.  
  226.             node -> Special . Gauge . LastPercentage = count;
  227.  
  228.             right = 0;
  229.  
  230.             if(count)
  231.             {
  232.                 LONG chunk = width / 10,i;
  233.                 UWORD fillPen = handle -> DrawInfo -> dri_Pens[FILLPEN];
  234.                 UWORD backPen = handle -> BackgroundPen;
  235.  
  236.                 left = 0;
  237.  
  238.                 for(i = 0 ; i < count ; i++)
  239.                 {
  240.                     LTP_SetAPen(rp,fillPen);
  241.                     RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + left + (chunk - 1) - 1,node -> Top + 1 + height - 1);
  242.  
  243.                     left += chunk;
  244.                     right += chunk;
  245.  
  246.                     LTP_SetAPen(rp,backPen);
  247.                     RectFill(rp,node -> Left + 2 + right - 1,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  248.                 }
  249.             }
  250.  
  251.             if(right < width)
  252.             {
  253.                 left    = right;
  254.                 right    = width;
  255.  
  256.                 LTP_SetAPen(rp,handle -> BackgroundPen);
  257.                 RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  258.             }
  259.         }
  260.     }
  261.  
  262.     node -> Current = percent;
  263.  
  264.     LTP_PutStorage(node);
  265. }
  266. #endif
  267.